package com.example.xd.commen_utils.installpackageinfo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;

/**
 * @auther XuDan on 2020/9/2.
 */
public class Main {
    public static void main(String[] args) {
//        int[] arr = {10, 17, 5, 6, 23, 77, 2, 50, 66, 1};
//        int[] arr2 = {1, 5, 8, 3, 6, 9};
//        String[] strings = {"a", "b", "c", "a", "f", "f", "f"};
//        method1(arr);
//        System.out.println(method2(arr2, 6));
//        method3(strings);


    }

    private static void method3(String[] strings) {
        ArrayList<String> list = new ArrayList<>(Arrays.asList(strings));
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println("---------");
        HashSet<String> set = new HashSet<>(list);
        list.clear();
        list.addAll(set);
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
    }

    private static int method2(int[] arr, int value) {
        Arrays.sort(arr);
        int low = 0;
        int high = arr.length - 1;
        while (low <= high) {
            int mid = low + (high - low) / 2;
            if (arr[mid] > value) {
                high = mid - 1;
            } else if (arr[mid] < value) {
                low = mid + 1;
            } else {
                return mid;
            }
        }
        return -1;
    }

    public static void method1(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < i; j++) {
                int temp;
                if (arr[i] < arr[j]) {
                    temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
